package org.gwtEss.other;

import org.gwtEss.client.border.RoundBorder;

import com.google.gwt.event.dom.client.MouseDownEvent;
import com.google.gwt.event.dom.client.MouseDownHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;

public abstract class Dragger extends Composite implements HasDragEvents{
	protected PanelWithMouseEvents ft = new PanelWithMouseEvents();
	@Override
	public void setWidget(Widget widget) {
		ft.setWidget(widget);
	}
	public abstract void onDrag(int mouseX, int mouseY, int deltaX, int deltaY);
	public abstract void onDragEnd(int mouseX, int mouseY, int deltaX, int deltaY);
	public abstract void onDragStart(int mouseX, int clientY);
	protected boolean isPreventDefault(int i, int j){
		return true; 
	}
	public Dragger() {
		initWidget(ft);
		ft.addMouseDownHandler(new MouseDownHandler(){
			int startX, startY; 
			public void onMouseDown(MouseDownEvent event) {
				startX = event.getClientX();
				startY = event.getClientY(); 
				onDragStart(event.getClientX(), event.getClientY());
				if (isPreventDefault(event.getClientX(), event.getClientY()))
					event.preventDefault();
				else 
					return;
				DragTrackNew dt = new DragTrackNew(){

					@Override
					public void onMouseMove(int mouseX, int mouseY) {
						onDrag(mouseX, mouseY, startX - mouseX, startY - mouseY);
					}

			
					@Override
					public void onMouseUp(int mouseX, int mouseY) {
						onDragEnd(mouseX, mouseY, startX - mouseX, startY - mouseY);
					}

					};
			
			}
			
		});
		
	}
	public Dragger(RoundBorder mainPanel) {
		this();
		setWidget(mainPanel);
	}
}
